//
//  QFXmppManager.h
//  ChatDemo
//  Copyright (c) 2013 北京千锋互联科技有限公司. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "XMPPFramework.h"//深度封装了xmpp协议的逻辑
#import "UserModel.h"//存储用户身份的数据模型
#import "MessageModel.h"//存储消息的数据模型

typedef enum {
    kMsgText = 1,//文字
    kMsgImage = 2,//图片
    kMsgVoice = 3,//音频
    kMsgImageUrl = 4,
    kMsgVoiceUrl = 5,
}MessageType;

@interface QFXmppManager : NSObject {
    // nsurlconnection
    XMPPStream *_xmppStream;
    //注册对应的block
    void (^saveRegCb)(BOOL ret, NSError *err);
    //登录对应的block
    void (^saveLoginCb)(BOOL ret, NSError *err);
    //获取好友列表对应的block
    void (^saveFriendsCb) (NSArray *) ;
    void (^saveMessageCb) (MessageModel *mm);
    //发送信息对应的block
    void (^saveSendMessageFinishCb)(BOOL ret);
    
    UserModel *_currUser;//用户
    BOOL isInRegisting;//标记是否正在注册
    NSMutableArray *_allFriendList;//好友列表
    XMPPRoster *xmppRoster;
    XMPPRosterCoreDataStorage *xmppRosterStorage;
}
/*服务器使用千锋部署好的openfire服务器:域名:1000phone.net，所以账号的命名必须是: xxxx@1000phone.net,其他的账号为非法账号;端口5222
 *客户端通过连接指定的服务器实现后续的功能
 *
 */
//返回xmpp管理类单例
+ (id)shareInstance;
// Jabber ID
//向服务器注册新用户
- (void)registerUser:(NSString *)jid
    withPassword:(NSString *)pass
    withCompletion:( void (^) (BOOL ret, NSError *err))cb;
//登录
- (void)loginUser:(NSString *)jid
         withPassword:(NSString *)pass
       withCompletion:( void (^) (BOOL ret, NSError *err))cb;

//上线
- (void)goOnline;
//获取好友列表
- (void)getAllFriends:(void (^) (NSArray *)) cb;
// callback
//接收消息
- (void)registerForMessage:( void (^) (MessageModel *mm) )cb;
//发送消息
- (void)sendMessage:(NSString *)msg withType:(MessageType)type toUser:(UserModel *)toUser withCompletion:(void (^)(BOOL ret))cb;
//添加好友
- (void)addFriendWithName:(NSString *)userName andMessage:(NSString *)message;

@end

